#include <stdio.h>
#include <e_file.h>
#include <string.h>

#define BUFFSIZE 32
int mycopy(int rfd,int wfd);
int main(int argc, char ** argv){
	int fd1 = 0,fd2 = 0;
	if(argc < 3){
		return -1;
	}
	fd1 = open (argv[1], O_RDONLY);
	if(-1 == fd1){
		perror ("open ()");
	}
	fd2 = open (argv[2], O_WRONLY | O_CREAT | O_TRUNC, 0666);
	if(-1 == fd2){
		perror ("open ()");
	}
	mycopy(fd1,fd2);
	close (fd1);
	close (fd2);
	return 0;
}

int mycopy(int rfd,int wfd)
{
	int cnt = 0;
	char buf[BUFFSIZE] = {0};
	while(1){
		cnt = read (rfd, buf, BUFFSIZE);
		if(-1 == rfd){
			fprintf(stderr, "read() failed!!!!\n");
			goto ERROR;
		}
		if(0 == cnt){
			break;
		}
		write (wfd, buf, cnt);
	}

ERROR:
	close (rfd);
	close (wfd);
	return -1;
}
